home *** CD-ROM | disk | FTP | other *** search
- #import "readline.h"
- #include <string.h>
- #include <stdlib.h>
-
- static char *buffer=NULL;
- static unsigned long length_of_buffer;
-
-
- char *readline(FILE *theFile)
- {
- void *ptr;
- int offset;
-
- if(buffer==NULL){
- buffer=(char *)malloc(64*sizeof(char));
- length_of_buffer=64;
- }
- ptr=NULL;
- offset=0;
- *buffer='\0';
- while(ptr=fgets(buffer+offset,length_of_buffer-offset,theFile), ((ptr!=NULL)&&(buffer[strlen(buffer)-1]!='\n'))){
- buffer=realloc((char *)buffer,length_of_buffer*2);
- offset=length_of_buffer-1;
- length_of_buffer*=2;
- }
-
- if(ptr==NULL)
- return NULL;
- else
- return buffer;
- }
-
- char *get_buffer()
- {
- return buffer;
- }
-